//
//  SmarterScroller.m
//  MapEdit
//
//  Created by Steven Canfield on 2/10/09.
//  Copyright 2009 University of Puget Sound. All rights reserved.
//

#import "SmarterScroller.h"

@implementation SmarterScroller

- (void)mouseDown:(NSEvent *)theEvent {
	/* Convert to local coordinates */
	NSPoint viewPoint = [self convertPoint:[theEvent locationInWindow] fromView:[[self window] contentView]];
	
	/* Make sure it's not the scroll knob */
	if( !NSPointInRect( viewPoint, [self rectForPart:NSScrollerKnob] )) {
		float adjustment = [self knobProportion];
		if( [self frame].size.width > [self frame].size.height ) {
			/* Horizontal */
			if( viewPoint.x  <= [self rectForPart:NSScrollerKnob].origin.x ) {
				adjustment = -1.0f * adjustment;
			}
		} else {
			/* Vertical */
			if( viewPoint.y  <= [self rectForPart:NSScrollerKnob].origin.y ) {
				adjustment = -1.0f * adjustment;
			}
		}
		[self setFloatValue: [self floatValue] + adjustment];
	}
	[super mouseDown:theEvent];
}

- (void)setFloatValue:(float)fv {
	[super setFloatValue:fv];
	[[self target]  performSelector:[self action] withObject:self];
}

@end
